import { smc } from "../../../../common/ecs/SingletonModuleComp";
import { RoleAttributeType } from "../../../../role/model/RoleEnum";
import { Role } from "../../../../role/Role";
import { ISkillReport } from "../../model/report/ISkillReport";

/** 角色普通攻击伤害计算
 * 普通攻击伤害 = 我攻击力*（1+我破甲-敌防御转换的减伤-敌破甲抵抗）*
 * （1+我的增伤-敌的减伤）*（1+我VIP增伤-敌VIP减伤）*（1+我职业增伤-敌职业减伤）
 * 
 * 注：1+我破甲-敌防御转换的减伤-敌破甲抵抗≥0.3；
 * 注：1+我的增伤-敌的减伤强制≥0.3；
 * 注：我的增伤 = 我的增伤 + 器专属增伤；
 * 注：职业增减伤的数值来源于器
 * 防御转换的减伤 = 防御力*0.0001/(1+防御力*0.0001)
 * 最终伤害 = 普通攻击伤害 * （1 + 额外伤害百分比）+ 额外真伤
*/
export class RoleDamageNormal {
    static getDamage(isr: ISkillReport, target: Role) {
        if(isr.caster){
            var caster = isr.caster;
            var atk = caster.atk;                                       //我攻击力
            var pj = caster.getNumericValue(RoleAttributeType.pj);      //我破甲
            var zs = caster.getNumericValue(RoleAttributeType.zs);      //我的增伤
            var vipzs = caster.getNumericValue(RoleAttributeType.vipzs);//我VIP增伤
            var fyjs = target.def*0.0001/(1+target.def*0.0001);         //敌防御转换的减伤
            var pjdk = target.getNumericValue(RoleAttributeType.pjdk);  //敌破甲抵抗
            var js = target.getNumericValue(RoleAttributeType.js);      //敌的减伤
            var vipjs = target.getNumericValue(RoleAttributeType.vipjs);      //敌VIP减伤
            var damageRatio = caster.getNumericValue(RoleAttributeType.damage_ratio);//额外伤害百分比
            var atkReal = caster.getNumericValue(RoleAttributeType.atk_real);//额外真伤
            zs += this.getQiZsToWork(caster, target);


            var baseDamage = atk * Math.max((1 + pj - fyjs - pjdk), 0.3) * (1 + zs - js) * (1 + vipzs - vipjs);
            var finalDamage = baseDamage * (1 + damageRatio) + atkReal;

            return Math.max(Math.round(finalDamage), 0);
        }else{
            var attackRatio = isr.skill.SkillModel.skillRatio;
            var damage =  attackRatio;
            return Math.max(Math.round(damage), 0);
        }
    }

    //获取对某一直接的增伤
    private static getQiZsToWork(caster: Role, target: Role): number{
        var targetWork = target.RoleModel.table.work;

        //@ts-ignore
        var zs = caster.getNumericValue(`zs_${targetWork}`);

        return zs;
    }
}